package lab03.test09;

import java.io.*;
import java.util.ArrayList;
import java.util.List;

public class Test09 {

    public static void main(String[] args) {

        //txt文件内容 - >
        //单步调试
        //断点

        List<Book> books = new ArrayList<Book>();

        String path = "D:\\book.txt";
        String path1 = "D:\\book1.txt";

        BufferedReader reader = null;
        BufferedWriter writer = null;

        try {
            reader = new BufferedReader(new FileReader(path));
            writer =new BufferedWriter(new FileWriter(path1));

            String line = "";


            while ( (line = reader.readLine() ) != null){

                Book book = new Book();
                String []c = line.split("\t");
                book.bookNo = Integer.parseInt(c[0]);
                book.bookName = c[1];
                book.version = c[2];
                book.price = Double.parseDouble(c[3]);
                book.sales = Double.parseDouble(c[4]);

                books.add(book);
            }

            int i = 1;
            for (Book b:books){
                if (i == 3){
                    b.price = b.price+20;
                }
                if (i == 4){
                    b.price = b.price+30;
                }
                i++;
            }

            for (Book b :books){
                writer.write(b.bookNo + "   "+b.bookName+"  "
                        +b.version+"    "+b.price+" "+
                        b.sales
                );
                writer.newLine();
            }

        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            try {
                reader.close();
                writer.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

    }
}
